﻿using pbvs.Models;
using System.Data.Entity;

namespace pbvs.Data
{
    public class PbvsContext : DbContext
    {
        public DbSet<CommutationVariable> Variables { get; set; }
        public DbSet<ValuationRequest> Requests { get; set; }
        public DbSet<ContentPage> ContentPages { get; set; }
        public DbSet<FormElement> FormElements { get; set; }
        public DbSet<File> Files { get; set; }
        public DbSet<Client> Clients { get; set; }
        public DbSet<Role> Roles { get; set; }
        public DbSet<Login> Logins { get; set; }
	    public DbSet<Default> Defaults { get; set; }

	    protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            modelBuilder.Entity<Login>().
                         HasMany(c => c.Roles).
                         WithMany(r => r.Logins).
                         Map(m =>
                                 {
                                     m.MapLeftKey("LoginId");
                                     m.MapRightKey("RoleId");
                                     m.ToTable("Logins_Roles");
                                 });
            base.OnModelCreating(modelBuilder);
        }
    }
}